<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="author" content="彭俊超">
    <title>js微博输入字数统计</title>
    <style>
        div{
            width:500px;
            height:300px;
            background-color:lightseagreen;
            margin:0 auto;
            padding:20px;
        }
        textarea{
            width:100%;
            height:200px;
            resize:none;
        }
        P{
            width:130px;
            height:50px;
            background-color:coral;
            margin:0 auto;
            margin-top:50px;
            border-radius:15px;
            line-height:50px;
            text-align: center;
        }
    </style>
</head>

<body>
<div>
    <textarea rows="" cols="" oninput="chang()" class="bb" placeholder="请输入内容"></textarea>
    <p></p>
</div>

<script src="./jquery.js"></script>
</body>

</html>
<script>
    var str = '0';
    var wen = document.querySelector('.bb')
    var p = document.querySelector('p');
    function chang(){
    var count = 0;
        str = wen.value;
        for(var i = 0; i < wen.value.length; i ++){
            if( str.charCodeAt(i) < 255){
                    count = count + 0.5;
                }else{
                    count = count + 1;
                }   
        }
         if(count > 30){
                    wen.style.color = 'red'
            }
            else{
                    wen.style.color = 'black';
            }
        p.innerHTML = '字数统计'+Math.ceil(count);
        
    }

</script>